//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/note_add_widget.dart';

/// 课程笔记头部显示组件
class NoteTitleWidget extends StatelessWidget {
  /// 关联id，章节id
  final String relationId;

  /// 关联名称，章节名
  final String relationName;

  /// 视频id
  final String videoId;

  const NoteTitleWidget({
    super.key,
    required this.relationId,
    required this.relationName,
    required this.videoId,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("noteTitleWidget 组件 -> build 方法执行 ===> ");
    debugPrint("");
    return Row(
      children: [
        _showContainer(context: context),
      ],
    );
  }

  /// 组件显示标签
  _showContainer({
    required BuildContext context,
  }) {
    return GestureDetector(
      onTap: () {
        _onTapFunAdd(context);
      },
      child: Container(
        width: 132,
        height: 48,
        decoration: BoxDecoration(
          color: colorBlue2,
          borderRadius: BorderRadius.all(Radius.circular(24)),
        ),
        child: _addNodeItem(),
      ),
    );
  }

  /// 添加笔记组件
  _addNodeItem() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SvgPicture.asset(
          "images/question/stem_node_icon.svg",
          width: 24,
          height: 24,
          color: colorBlue1,
        ),
        Padding(
          padding: EdgeInsets.only(bottom: 5),
          child: Text(
            "记笔记",
            style: FontUtil.fontBlue1(18),
          ),
        ),
      ],
    );
  }

  /// 添加方法
  void _onTapFunAdd(BuildContext context) {
    _showPopupAdd(context: context);
  }

  /// 显示添加的弹出层
  _showPopupAdd({required BuildContext context}) async {
    showModalBottomSheet<int>(
      context: context,
      // 设置底部弹出框全屏显示
      isScrollControlled: true,
      // 点击遮罩层是否可以关闭
      // isDismissible: false,
      // 自定义弹出层高度
      // constraints: BoxConstraints(maxHeight: px408),
      // 自定义圆角
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(30),
          topRight: Radius.circular(30),
        ),
      ),
      builder: (context) {
        return SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.only(
              bottom: MediaQuery.of(context).viewInsets.bottom,
            ),
            child: NoteAddWidget.video(
              relationId: relationId,
              relationName: relationName,
              videoId: videoId,
            ),
          ),
        );
      },
    );
  }
}
